﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShiXuLong.Model;
using ShiXuLong.Service;
using System.Web.Security;

namespace ShiXuLong.Admin.Controllers
{
    public class LoginController : Controller
    {
        Login lg = new Service.Login();
        // GET: Login

        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 登录页面
        /// </summary>
        /// <returns></returns>
        public ActionResult LoginView()
        {

            return View();
        }

        /// <summary>
        /// 登录页面
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public ActionResult Login(string username, string password)
        {
            var res = lg.UserLogin(username, password);
            if (res)
            {
                FormsAuthentication.SetAuthCookie(username, true);
                return Json(new { msg = "登录成功", success = true });
            }
            else
            {
                return Json(new { msg = "登录失败", success = false });
            }

        }

        /// <summary>
        /// 退出登录方法
        /// </summary>
        /// <returns></returns>
        public ActionResult SignOut()
        {
            FormsAuthentication.SignOut();

            return Redirect("/Home/Index");
        }

        public ActionResult UserCenterView()
        {

            return View();
        }
    }
}